package com.yiwei.jmx.view;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;


import com.allen.library.SuperButton;
import com.yiwei.jmx.R;
import com.yiwei.jmx.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-5-22.
 */

public class SureIdcardIndentityDilaog extends Dialog {


    @BindView(R.id.btn_cancel)
    ImageView btnCancel;
    @BindView(R.id.edit_realname)
    EditText editRealname;
    @BindView(R.id.edit_idcard_no)
    EditText editIdcardNo;
    @BindView(R.id.btn_edit)
    SuperButton btnEdit;
    @BindView(R.id.btn_upload)
    SuperButton btnUpload;
    private Context context;


    public SureIdcardIndentityDilaog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public SureIdcardIndentityDilaog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_sure_idcard_identity);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.gravity = Gravity.CENTER;
        if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {// 横屏
            lp.width = Util.getDisplayMetrics(context).heightPixels / 10 * 8;
        } else {
            lp.width = Util.getDisplayMetrics(context).widthPixels / 10 * 8;
        }
        mWindow.setAttributes(lp);


    }


    public void setData(String idcard_no,
                        String realname) {
        editIdcardNo.setText(idcard_no);
        editRealname.setText(realname);
    }


    private OnChooseListener onChooseListener;

    public SureIdcardIndentityDilaog setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
        return this;
    }

    @OnClick({R.id.btn_cancel, R.id.btn_edit, R.id.btn_upload})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.btn_edit:
                dismiss();
                break;
            case R.id.btn_upload:
                if (onChooseListener != null) {
                    onChooseListener.onSuccess();
                }
                break;
        }
    }


    public interface OnChooseListener {
        void onSuccess();
    }
}
